﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CID.Domain.Users;

namespace CID.Web.Support
{
    public class CIDAuthorizeAttribute : AuthorizeAttribute
    {
        public UserRole[] UserRoles { get; private set; }

        public CIDAuthorizeAttribute(params UserRole[] userRoles)
            : base()
        {
            Roles = String.Join(", ", userRoles.Select(x => x.ToString()).ToArray());
            UserRoles = userRoles;
        }

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            return (httpContext.Request.IsLocal || base.AuthorizeCore(httpContext));
        }
    }
}